/*修改密码*/
function updatePwd(user) {
    console.log(user)
    let content = '<div style="width:350px;">\n' +
        '        <form class="layui-form layui-form-pane" action="" style="text-align: center;">\n' +
        '            <div class="layui-form-item">\n' +
        '                <label class="layui-form-label">请输入旧密码</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="password" id="pwd" name="pwd" lay-verify="required" placeholder="请输入" autocomplete="off"\n' +
        '                        class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-form-item">\n' +
        '                <label class="layui-form-label">请输入新密码</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="password" id="pwd1" name="pwd1" lay-verify="required" placeholder="请输入" autocomplete="off"\n' +
        '                        class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '            <div class="layui-form-item">\n' +
        '                <label class="layui-form-label">请确认新密码</label>\n' +
        '                <div class="layui-input-inline">\n' +
        '                    <input type="password" id="pwd2" name="pwd2" lay-verify="required" placeholder="请输入" autocomplete="off"\n' +
        '                        class="layui-input">\n' +
        '                </div>\n' +
        '            </div>\n' +
        '        </form>\n' +
        '    </div>';
    layer.open({
        area: ['340px', '265px'],
        content: content,
        title: '修改密码',
        btn: ['确认修改', '取消修改'],
        btnAlign: 'c',
        skin: 'layui-layer-molv',
        time: 0,
        yes: function (index, layero) {
            let pwdK1 = $("#pwd").val();
            let pwdK2 = $("#pwd1").val();
            let pwdK3 = $("#pwd2").val();
            if (pwdK2 != pwdK3) {
                layer.msg("两次密码输入不一样，请重新输入！", {
                    title: '温馨提示',
                    time: 0,
                    btn: '确认',
                    btnAlign: 'c',
                    yes: function () {
                        layer.closeAll();
                    }
                })
                return;
            }
            if (user.pwd == pwdK1) {
                $.post("/userLogin/updatePwd", "id=" + user.id + "&pwd=" + pwdK2, function (dataW) {
                    if (dataW) {
                        layer.msg("恭喜您：密码修改成功！", {
                            title: '温馨提示',
                            time: 0,
                            btn: '确认',
                            btnAlign: 'c',
                            yes: function () {
                                layer.closeAll();
                            }
                        })
                    } else {
                        layer.msg("恭喜您：密码修改失败！", {
                            title: '温馨提示',
                            time: 0,
                            btn: '确认',
                            btnAlign: 'c',
                            yes: function () {
                                layer.closeAll();
                            }
                        })
                    }
                });
            } else {
                layer.msg("初始密码错误！请重新输入", {
                    title: '温馨提示',
                    time: 0,
                    btn: '确认',
                    btnAlign: 'c',
                })
            }
            return false;
        }
    });
}


/*权限分配*/
let dataA = $(".zwqx").val();
dataA = JSON.parse(dataA);//转换成数组对象
let arryA = new Array();
for (let i = 0; i < dataA.length; i++) {/*得到固定的格式11111*/
    arryA.push('           <li>\n' +
        '                        <a onclick="xadmin.add_tab(\'' + dataA[i].auth + '\',\'' + dataA[i].path + '\')">\n' +
        '                            <i class="iconfont">&#xe6a7;</i>\n' +
        '                            <cite>' + dataA[i].auth + '</cite>' +
        '                       </a>\n' + '');
}
//定义渲染变量
let one = "";
for (let i = 0; i < dataA.length; i++) {

    if (dataA[i].id == 17 || dataA[i].id == 18 || dataA[i].id == 19 || dataA[i].id == 20 || dataA[i].id == 21) {
        one = one + '<li>\n' +
            '                <a href="javascript:;">\n' +
            '                    <i class="iconfont left-nav-li" lay-tips="系统设置">&#xe6ce;</i>\n' +
            '                    <cite>系统设置</cite>\n' +
            '                    <i class="iconfont nav_right">&#xe697;</i></a>\n' +
            '                <ul class="sub-menu">';
        for (let j = 17; j < 22; j++) {
            for (let k = 0; k < dataA.length; k++) {
                if (dataA[k].id == j) {
                    one = one + arryA[k];
                    if (dataA[k].id == 19) {
                        console.log("-------------------------------")
                        one = one + '<ul class="sub-menu">\n' +
                            '                    <li>\n' +
                            '                        <a onclick="xadmin.add_tab(\'权限信息管理\',\'/zwqx/zw2\')">\n' +
                            '                            <i class="iconfont">&#xe6a7;</i>\n' +
                            '                            <cite>权限信息管理</cite></a>\n' +
                            '                    </li>' +
                            '      </ul>'
                    }
                    one = one + '</li>'
                    break;
                }
            }
        }
        break;
    }
}
one = one + '</ul>'

//渲染页面
$("#nav").html(one);


/*个人信息*/
function selUserInfo(user) {

    $.post("/userLogin/selUserInfo", "id=" + user.id, function (dataL) {
        console.log(dataL)
        let content = '  <center>\n' +
                '  <table style="height: 170px;text-align: center;font-weight: 700;width: 300px;border-color: #d6e9c6" border="1px" >\n' +
            '    <tr>\n' +
            '      <td>账号： </td> \n' +
            '      <td>'+dataL.username+'</td>\n' +
            '    </tr>\n' +
            '    <tr >\n' +
            '      <td>姓名：</td> \n' +
            '      <td>'+dataL.name+'</td>\n' +
            '    </tr>\n' +
            '    <tr>\n' +
            '      <td>部门：</td> \n' +
            '      <td>'+dataL.department.departmentname+'</td>\n' +
            '    </tr>\n' +
            '    <tr>\n' +
            '      <td>职位：</td> \n' +
            '      <td>'+dataL.jobtitle.job+'</td>\n' +
            '    </tr>\n' +
            '    <tr>\n' +
            '      <td>状态：</td> \n' +
            '      <td>正常</td>\n' +
            '    </tr>\n' +
            '  </table>\n' +
            '</center>';
        layer.alert(content,{
            btnAlign:'c',
            title:'个人信息',
            skin: 'layui-layer-molv',
        })
    });


}